package com.lancoo.answer.view.adapter

import com.chad.library.adapter.base.entity.node.BaseNode
import com.chad.library.adapter.base.provider.BaseNodeProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lancoo.answer.R
import com.lancoo.answer.databinding.EvItemSentenceSubBinding
import com.lancoo.answer.model.bean.Comment
import com.lancoo.answer.util.HtmlUtils

/**
 * Created by wealive on 2022/7/21.
 *
 *
 */
class SentenceProvider : BaseNodeProvider() {
    override val itemViewType: Int
        get() = 1
    override val layoutId: Int
        get() = R.layout.ev_item_sentence_sub

    override fun convert(helper: BaseViewHolder, item: BaseNode) {
        val binding = EvItemSentenceSubBinding.bind(helper.itemView)
        val subSentence = item as Comment
        when (subSentence.Type) {
            "warn" -> {
                binding.ivLogo.setImageResource(R.mipmap.ev_icon_warns)
            }
            "error" -> {
                binding.ivLogo.setImageResource(R.mipmap.ev_icon_wrongs)
            }
            "error_trp" -> {
                binding.ivLogo.setImageResource(R.mipmap.ev_icon_tips)
            }
            "great" -> {
                binding.ivLogo.setImageResource(R.mipmap.ev_icon_recommended)
            }
        }
        val comment = StringBuilder()
        val msg = subSentence.Msg.replace("<b>", "<font color=\"#0099ff\">")
            .replace("</b>", "</font>")
        comment.append("<b>[${subSentence.Cat}]</b>$msg")
        binding.tvComment.text = HtmlUtils.setText(comment.toString())
    }
}